//
//  MyTableViewCell.m
//  Cell
//
//  Created by WLJ on 19/10/2016.
//  Copyright © 2016 WLJ. All rights reserved.
//

#import "MyTableViewCell.h"
#import <Masonry/Masonry.h>
#import <Wonderful/Wonderful-umbrella.h>
#import <Colours/Colours-umbrella.h>
#import <HYBImageCliped/HYBImageCliped-umbrella.h>
#define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
@interface MyTableViewCell ()
@property(nonatomic,strong)UIView * stackView;
@property(nonatomic,strong)UIView  * tipBackView;

//@property(nonatomic,strong)FUIButton * menuBackButton;

@end

@implementation MyTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.layer.shadowColor = [UIColor dimGray].CGColor;
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = [UIColor clearColor];
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsMake(4, 4, 4, 4));
        }];
        [self setSubviews];
        [self setContriants];
        
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)setSubviews{
    [self.rightTopBtn setTitle:@"发送小组消息" forState:UIControlStateNormal];
    self.rightTopBtn.buttonColor = [UIColor moneyGreenColor];
    self.rightTopBtn.shadowColor = [UIColor hollyGreenColor];
    self.rightTopBtn.shadowHeight = 1.0f;
    self.rightTopBtn.cornerRadius = 6.0f;
    self.rightTopBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.rightTopBtn setTitleColor:[UIColor whiteSmoke] forState:UIControlStateNormal];
//    [self.tipBackView addSubview:self.rightTopBtn];
    
    
    self.stackView.backgroundColor = [UIColor whiteSmoke];
//    self.stackView.layer.shadowColor = [UIColor goldColor].CGColor;
//    self.stackView.layer.shadowOffset = CGSizeMake(2, 2);
    [self.stackView hyb_addCornerRadius:4];
    [self.contentView addSubview:self.stackView];
    
    self.tipBackView.backgroundColor = [UIColor babyBlueColor];
    [self.tipBackView hyb_addCornerRadius:4];
    [self.contentView addSubview:self.tipBackView];
    
    [self.header hyb_addCornerRadius:rowHeight*0.8*0.3*0.5];
    self.header.clipsToBounds = YES;
    [self.stackView addSubview:self.header];
    
    self.name.textColor = [UIColor blackColor];
    self.name.font = [UIFont boldFlatFontOfSize:16];
    [self.stackView addSubview:self.name];
    
    self.classs.icon.image = [UIImage imageNamed:@"Bundel.bundle/班"];;
    self.physical.icon.image = [UIImage imageNamed:@"Bundel.bundle/专"];
    self.numb.icon.image = [UIImage imageNamed:@"Bundel.bundle/号"];
    self.phone.icon.image = [UIImage imageNamed:@"Bundel.bundle/电"];
    
    [self.stackView addSubview:self.classs];
    [self.stackView addSubview:self.physical];
    [self.stackView addSubview:self.numb];
    [self.stackView addSubview:self.phone];
    
    self.tip.textColor = [UIColor whiteSmoke];
    self.tip.font = [UIFont systemFontOfSize:13.5];
    self.tip.text = @"所属项目:___";
    [self.tipBackView addSubview:self.tip];
    
    self.btn0.buttonColor = [UIColor babyBlueColor];
    self.btn0.shadowColor = [UIColor steelBlueColor];
    self.btn0.shadowHeight = 0.5f;
    self.btn0.cornerRadius = 6.0f;

    self.btn1.buttonColor = [UIColor babyBlueColor];
    self.btn1.shadowColor = [UIColor steelBlueColor];
    self.btn1.shadowHeight = 0.5f;
    self.btn1.cornerRadius = 6.0f;
    
    self.btn2.buttonColor = [UIColor babyBlueColor];
    self.btn2.shadowColor = [UIColor steelBlueColor];
    self.btn2.shadowHeight = 0.5f;
    self.btn2.cornerRadius = 6.0f;
    
    self.btn3.buttonColor = [UIColor babyBlueColor];
    self.btn3.shadowColor = [UIColor steelBlueColor];
    self.btn3.shadowHeight = 0.5f;
    self.btn3.cornerRadius = 6.0f;
    
    [self.btn0 setTitle:@"进度" forState:UIControlStateNormal];
    [self.btn1 setTitle:@"组员" forState:UIControlStateNormal];
    [self.btn2 setTitle:@"修改" forState:UIControlStateNormal];
    [self.btn3 setTitle:@"删除" forState:UIControlStateNormal];
    
    self.btn0.titleLabel.font = [UIFont systemFontOfSize:10];
    self.btn1.titleLabel.font = [UIFont systemFontOfSize:10];
    self.btn2.titleLabel.font = [UIFont systemFontOfSize:10];
    self.btn3.titleLabel.font = [UIFont systemFontOfSize:10];
    
    [self.btn0 setTitleColor:[UIColor whiteSmoke] forState:UIControlStateNormal];
    [self.btn1 setTitleColor:[UIColor whiteSmoke] forState:UIControlStateNormal];
    [self.btn2 setTitleColor:[UIColor whiteSmoke] forState:UIControlStateNormal];
    [self.btn3 setTitleColor:[UIColor easterPinkColor] forState:UIControlStateNormal];
    
    [self.stackView addSubview:self.btn0];
    [self.stackView addSubview:self.btn1];
    [self.stackView addSubview:self.btn2];
    [self.stackView addSubview:self.btn3];
    
    [self.stackView addSubview:self.rightTopBtn];
}
-(void)setContriants{
    [self.tipBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(rowHeight*0.20);
    }];
    [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(8);
        make.right.mas_equalTo(-8);
        make.bottom.mas_equalTo(0);
        make.top.mas_equalTo(self.tipBackView.mas_bottom).offset(-2);
    }];
    
//    [self.rightTopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.mas_equalTo(self.tipBackView);
//        make.right.mas_equalTo(0);
//        make.height.mas_equalTo(self.rightTopBtn.superview.mas_height);
//    }];
    
//    [self.menuBackButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(2);
//        make.centerY.mas_equalTo(self.tipBackView);
//        make.height.width.mas_equalTo(self.rightTopBtn.superview.mas_height).multipliedBy(0.8);
//    }];
    
//    [self.tip mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.mas_equalTo(self.tipBackView);
//        make.left.mas_equalTo(self.menuBackButton.mas_right).offset(2);
//        make.height.mas_equalTo(self.rightTopBtn.superview.mas_height);
//    }];
    
    [self.tip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(2);
        make.centerY.mas_equalTo(self.tipBackView);
        make.height.mas_equalTo(self.rightTopBtn.superview.mas_height);
    }];
    
    [self.header mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(4);
        make.height.mas_equalTo(rowHeight*0.8*0.30);
        make.width.mas_equalTo(self.header.mas_height).multipliedBy(1.0);
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.header);
        make.left.mas_equalTo(self.header.mas_right).offset(2);
        make.height.mas_equalTo(self.header.mas_height).multipliedBy(0.8);
    }];
    
    [self.classs mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(self.header.mas_bottom).offset(2);
        make.height.mas_equalTo(rowHeight*0.8*0.19);
    }];
    [self.physical mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.classs);
        make.top.mas_equalTo(self.classs.mas_bottom).offset(0);
        make.height.mas_equalTo(self.classs);
    }];
    [self.numb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(SCREENWIDTH*0.6);
        make.top.mas_equalTo(self.name.mas_bottom).offset(2);
        make.height.mas_equalTo(self.classs);
    }];
    [self.phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.numb);
        make.top.mas_equalTo(self.numb.mas_bottom).offset(0);
        make.height.mas_equalTo(self.classs);
    }];
    
    static float leading = 10;
    static float space = 20;
    [self.btn0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(leading);
        //make.right.mas_equalTo(self.btn1.mas_left).offset(-space);
        make.top.greaterThanOrEqualTo(self.physical.mas_bottom).offset(4);
        make.bottom.greaterThanOrEqualTo(self.stackView);
        make.height.mas_equalTo(rowHeight*0.8*0.18);
    }];
    [self.btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.btn0.mas_right).offset(space);
        //make.right.mas_equalTo(self.btn2.mas_left).offset(-space);
        make.centerY.mas_equalTo(self.btn0);
        make.width.height.mas_equalTo(self.btn0);
    }];
    [self.btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.btn1.mas_right).offset(space);
        //make.right.mas_equalTo(self.btn3.mas_left).offset(-space);
        make.centerY.mas_equalTo(self.btn0);
        make.width.height.mas_equalTo(self.btn0);
    }];
//    [self.btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(self.btn2.mas_right).offset(space);
//        make.right.mas_equalTo(-leading);
//        make.centerY.mas_equalTo(self.btn0);
//        make.width.height.mas_equalTo(self.btn0);
//    }];
    
    [self.btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.btn2.mas_right).offset(space);
        make.centerY.mas_equalTo(self.btn0);
        make.width.height.mas_equalTo(self.btn0);
    }];
    
    [self.rightTopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.btn3.mas_right).offset(space+leading);
        make.right.mas_equalTo(-2);
        make.centerY.mas_equalTo(self.btn0);
        make.height.mas_equalTo(self.btn0);
    }];
}


-(UIView *)tipBackView{
    if (!_tipBackView) {
        _tipBackView = [UIView new];
    }
    return _tipBackView;
}
-(UILabel *)tip{
    if (!_tip) {
        _tip = [UILabel new];
    }
    return _tip;
}

-(UIImageView *)header{
    if (!_header ) {
        _header = [UIImageView new];
    }
    return _header;
}
-(FUIButton *)rightTopBtn{
    if (!_rightTopBtn) {
        _rightTopBtn = [FUIButton new];
    }
    return _rightTopBtn;
}
-(UILabel *)name{
    if (!_name) {
        _name = [UILabel new];
    }
    return _name;
}
-(MyLabelView *)classs{
    if (!_classs) {
        _classs =[[MyLabelView alloc]init];
    }
    return _classs;
}
-(MyLabelView *)phone{
    if (!_phone) {
        _phone = [[MyLabelView alloc]init];
    }
    return  _phone;
}
-(MyLabelView *)physical{
    if (!_physical) {
        _physical = [[MyLabelView alloc]init];
    }
    return _physical;
}
-(MyLabelView *)numb{
    if (!_numb) {
        _numb = [[MyLabelView alloc]init];
    }
    return _numb;
}
-(UIView *)stackView{
    if (!_stackView) {
        _stackView = [UIView new];
    }
    return _stackView;
}

-(FUIButton *)btn0{
    if (!_btn0) {
        _btn0 = [FUIButton new];
    }
    return _btn0;
}
-(FUIButton *)btn1{
    if (!_btn1) {
        _btn1 = [FUIButton new];
    }
    return _btn1;
}
-(FUIButton *)btn2{
    if (!_btn2) {
        _btn2 = [FUIButton new];
    }
    return _btn2;
}
-(FUIButton *)btn3{
    if (!_btn3) {
        _btn3 = [FUIButton new];
    }
    return _btn3;
}


//-(FUIButton *)menuBackButton{
//    if (!_menuBackButton) {
//        _menuBackButton = [FUIButton new];
//        [_menuBackButton setBackgroundImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
//    }
//    return _menuBackButton;
//}
@end
